package source

import "kumachan/standalone/util/richtext"


type Location struct {
	File  File
	Pos   Position
}
// note: File should be comparable
type File interface {
	GetKey() FileKey
	DescribePosition(Position) string
	FormatMessage(Position, richtext.Block) richtext.Block
}
type FileKey struct {
	Context  string
	Path     string
}
type Position struct {
	Index1  uint32
	Index2  uint32
}
func (key FileKey) String() string {
	return (key.Context + "[" + key.Path + "]")
}
func (l Location) FileDesc() string {
	if l.File != nil {
		return l.File.GetKey().String()
	} else {
		return "(nil)"
	}
}
func (l Location) PosDesc() string {
	if l.File != nil {
		return l.File.DescribePosition(l.Pos)
	} else {
		return "(nil)"
	}
}
func (l Location) FormatMessage(b richtext.Block) richtext.Block {
	if l.File != nil {
		return l.File.FormatMessage(l.Pos, b)
	} else {
		return b
	}
}


